package com.mdb.open.trade.resource.trade;

/*
* Copyright (C), 2017-2019 澳发科技(MDB)
* FileName: RepaymentOrderService.java
* Author:   you.yichao
* Date:     2019-06-29
* History:
* <author>          <time>          <version>          <desc>
* you.yichao         2019-06-29          V1.00        代码生成器初始生成代码
* -----------------------------------------------------------
* 作者姓名           修改时间           版本号            描述
*/


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdb.bc.api.data.ListResultEx;
import com.mdb.bc.logger.LogAnnotation;
import com.mdb.bc.utils.ObjectUtil;
import com.mdb.bc.web.support.SuperResources;
import com.mdb.open.common.enums.trade.status.RepaymentOrderStatusEnum;
import com.mdb.open.trade.domain.bo.trade.QueryRepaymentOrderPageListBo;
import com.mdb.open.trade.domain.dto.trade.QueryRepaymentOrderPageListDto;
import com.mdb.open.trade.domain.po.trade.RepaymentOrder;
import com.mdb.open.trade.domain.vo.trade.RepaymentOrderVo;
import com.mdb.open.trade.service.trade.TfRepaymentOrderService;
import com.mdb.user.LoginUserInfoHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类描述：
 *  融资还款单表 前端控制器
 *
 * @author you.yichao
 * @date 2019-06-29
 */
@RestController
@RequestMapping("tf/repayment")
@Api(tags = "贸易金融还款")
public class RepaymentOrderResource extends SuperResources {

    @Autowired
    TfRepaymentOrderService tfRepaymentOrderService;

    @Autowired
    LoginUserInfoHelper loginUserInfoHelper;


    @LogAnnotation
    @ApiOperation("融资还款单表列表 - 分页查询")
    @GetMapping("/page_list")
    public ListResultEx<RepaymentOrderVo> findByCondition(@ModelAttribute QueryRepaymentOrderPageListDto repaymentOrderDto) {


        QueryRepaymentOrderPageListBo bo = new QueryRepaymentOrderPageListBo();
        bo.setApplyOrderNo(repaymentOrderDto.getApplyOrderNo());
        bo.setBusinessNo(repaymentOrderDto.getBusinessNo());
        bo.setMerchantNo(repaymentOrderDto.getMerchantNo());
        bo.setCustomerCode(loginUserInfoHelper.getCustomerCode(Boolean.TRUE));
        bo.setMerchantName(repaymentOrderDto.getMerchantName());
        bo.setStartDate(repaymentOrderDto.getStartDate());
        bo.setEndDate(repaymentOrderDto.getEndDate());
        if (ObjectUtil.isNotEmpty(repaymentOrderDto.getStatus())) {
            bo.setOverdueStatus(repaymentOrderDto.getStatus().getOverdueStatusEnum());
            bo.setRepaymentStatus(repaymentOrderDto.getStatus().getRepaymentOrderStatusEnum());
        } else {
            bo.setRepaymentStatus(RepaymentOrderStatusEnum.IN_REPAYMENT);
        }
        bo.setPageNo(repaymentOrderDto.getPageNo());
        bo.setPageSize(repaymentOrderDto.getPageSize());
        bo.setSort(repaymentOrderDto.getSort());
        bo.setOrder(repaymentOrderDto.getOrder());

        //分页查询
        IPage<RepaymentOrder> page = tfRepaymentOrderService.pageQuery(bo);

        return this.convertListResult(page, repaymentOrder -> {
            RepaymentOrderVo vo = new RepaymentOrderVo();
            vo.setApplyOrderNo(repaymentOrder.getApplyOrderNo());
            vo.setRepaymentOrderNo(repaymentOrder.getRepaymentOrderNo());
            vo.setLoanContractNo(repaymentOrder.getLoanContractNo());
            vo.setBusinessNo(repaymentOrder.getBusinessNo());
            vo.setCustomerCode(repaymentOrder.getCustomerCode());
            vo.setCustomerName(repaymentOrder.getCustomerName());
            vo.setMerchantNo(repaymentOrder.getMerchantNo());
            vo.setMerchantName(repaymentOrder.getMerchantName());
            vo.setReceiveSubAcc(repaymentOrder.getReceiveSubAcc());
            vo.setLoanDate(repaymentOrder.getLoanDate());
            vo.setValueDate(repaymentOrder.getValueDate());
            vo.setExpiryDate(repaymentOrder.getExpiryDate());
            vo.setTotalRate(repaymentOrder.getTotalRate());
            vo.setAddRate(repaymentOrder.getAddRate());
            vo.setFeeRate(repaymentOrder.getFeeRate());
            vo.setOverdueRate(repaymentOrder.getOverdueRate());
            vo.setLoanTerm(repaymentOrder.getLoanTerm());
            vo.setCcy(repaymentOrder.getCcy());
            vo.setLoanAmount(repaymentOrder.getLoanAmount());
            vo.setInterest(repaymentOrder.getInterest());
            vo.setEnableTotalAmount(repaymentOrder.getEnableTotalAmount());
            vo.setEnableInterest(repaymentOrder.getEnableInterest());
            vo.setEnablePrinPenalty(repaymentOrder.getEnablePrinPenalty());
            vo.setEnableInterPenalty(repaymentOrder.getEnableInterPenalty());
            vo.setEnablePenalty(repaymentOrder.getEnablePrinPenalty().add(repaymentOrder.getEnableInterPenalty()));
            vo.setWaitPayTotalAmount(repaymentOrder.getWaitPayTotalAmount());
            vo.setWaitPrincipal(repaymentOrder.getWaitPrincipal());
            vo.setWaitInterest(repaymentOrder.getWaitInterest());
            vo.setWaitPrinPenalty(repaymentOrder.getWaitPrinPenalty());
            vo.setWaitInterPenalty(repaymentOrder.getWaitInterPenalty());
            vo.setPaidTotalAmount(repaymentOrder.getPaidTotalAmount());
            vo.setPaidInterest(repaymentOrder.getPaidInterest());
            vo.setPaidPrincipal(repaymentOrder.getPaidPrincipal());
            vo.setPaidPrinPenalty(repaymentOrder.getPaidPrinPenalty());
            vo.setPaidInterPenalty(repaymentOrder.getPaidInterPenalty());
            vo.setOverdueDays(repaymentOrder.getOverdueDays());
            vo.setOverdueStatus(repaymentOrder.getOverdueStatus());
            vo.setRepaymentStatus(repaymentOrder.getRepaymentStatus());
            vo.setCreateTime(repaymentOrder.getCreateTime());
            vo.setUpdateTime(repaymentOrder.getUpdateTime());
            return vo;
        });
    }

}
